<?php 
$lang="KR";
$company="elitech";
$code="345";
$username="Đặng Tuấn Anh";
//$lang=$_REQUEST['lang'];
//$company=$_REQUEST['company'];
//$code=$_REQUEST['code'];
//$username=$_REQUEST['username'];
$idemployees=$_REQUEST['idemployees'];

$temp = explode(";",$idemployees);
$connection = mysql_connect("1.234.53.52", "cam", "5678" ) ;
//$connection = mysql_connect("localhost", "root", "root" ) ;
mysql_select_db("elihan", $connection);
mysql_query("set names 'utf8'");
$selectdatabase = mysql_query("SELECT am.DatabaseName,am.Logo from ac_eli_manager am where am.KeyName='$company' and am.`Status` = 2");
$result = mysql_fetch_assoc($selectdatabase);
$db= $result['DatabaseName'];
echo $db;
mysql_select_db($db, $connection);


if (empty($lang) || $lang == "EN") {
	$value = "value/value_en.php";
} else if($lang == "VN") {
	$value = "value/value_vn.php";
}
else {
	$value = "value/value_kr.php";
}
include($value);
$result=mysql_query("SELECT c.`name`,c.signDay,c.content,c.totalValue,c.prepaidMoney,c.expectedDay,c.nameCompany FROM contract c WHERE  c.`code`='$code';");
while ($row = mysql_fetch_array($result))
{
	$name = $row['name'];
	$signDay = $row['signDay'];
	$content = $row['content'];
	
	$totalValue = $row['totalValue'];
	$prepaidMoney = $row['prepaidMoney'];
	$expectedDay = $row['expectedDay'];
	
	$nameCompany = $row['nameCompany'];

}

// file 03-gmail.php
		
		//NhÃƒÂºng thÃ†Â° viÃ¡Â»â€¡n phpmailer
		require_once('class.phpmailer.php');
		
		//KhÃ¡Â»Å¸i tÃ¡ÂºÂ¡o Ã„â€˜Ã¡Â»â€˜i tÃ†Â°Ã¡Â»Â£ng
		$mail = new PHPMailer();
		
		$mail->IsSMTP(); // GÃ¡Â»ï¿½i Ã„â€˜Ã¡ÂºÂ¿n class xÃ¡Â»Â­ lÃƒÂ½ SMTP
		//$mail->Host       = "mail.zend.vn"; // tÃƒÂªn SMTP server
		$mail->SMTPDebug  = 2;                    // enables SMTP debug information (for testing)
		                                           // 1 = errors and messages
		                                           // 2 = messages only
		$mail->SMTPAuth   = true;                  // SÃ¡Â»Â­ dÃ¡Â»Â¥ng Ã„â€˜Ã„Æ’ng nhÃ¡ÂºÂ­p vÃƒÂ o account
		$mail->SMTPSecure = "ssl";
		$mail->Host       = "smtp.gmail.com";     // ThiÃ¡ÂºÂ¿t lÃ¡ÂºÂ­p thÃƒÂ´ng tin cÃ¡Â»Â§a SMPT
		$mail->Port       = 465;                     // ThiÃ¡ÂºÂ¿t lÃ¡ÂºÂ­p cÃ¡Â»â€¢ng gÃ¡Â»Â­i email cÃ¡Â»Â§a mÃƒÂ¡y
		$mail->Username   = "elisoftmailserver@gmail.com"; // SMTP account username
		$mail->Password   = "1234567892727";         // SMTP account password
		
		//Thiet lap thong tin nguoi gui va email nguoi gui
		//$yesterday=date("Y-m-d", time() - 86400);
		$mail->SetFrom('elisoftmailserver@gmail.com',$company.' - '.$l_contract);
		
		//ThiÃ¡ÂºÂ¿t lÃ¡ÂºÂ­p thÃƒÂ´ng tin ngÃ†Â°Ã¡Â»ï¿½i nhÃ¡ÂºÂ­n
		//$mail->AddAddress("klkim169@gmail.com", "klkim");
		
		$temp = explode(";",$idemployees);
		$sql="SELECT e.Email,e.FullName FROM employee e WHERE ";
		for ($i=0;$i<count($temp)-1;$i++){
			$sql.="e.IDEmployee='".$temp[$i]."' OR ";
		}
		$sql.="e.IDEmployee='".$temp[$i]."'";
		$q=mysql_query($sql);
		while ($row=mysql_fetch_array($q)){
			$mail->AddAddress($row['Email'], $row['FullName']);
		}
		
		$mail->Subject    =  $company.' - '.$name;
		
		$mail->CharSet = "utf-8";
		$mail->IsHTML(true);
	
		
		$body='';
		$body.='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
				<html xmlns="http://www.w3.org/1999/xhtml">
				<head>
				<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
				<title>Untitled Document</title>
				</head>
				
				<body>
				<table class="ftable" width="100%" cellspacing="1" cellpadding="0" border="0">
				<tbody>
				 <tr height="40px">
	                <th style="min-width: 170px;background: #4f81bd;height: 30px;color: white;font-size: 16px;font-weight: bold;">'.$l_name_contract.'</th>
	                <th style="min-width: 90px;background: #4f81bd;height: 30px;color: white;font-size: 16px;font-weight: bold;">'.$l_signDay_contract.'</th>
	                <th style="min-width: 80px;background: #4f81bd;height: 30px;color: white;font-size: 16px;font-weight: bold;">'.$l_content_contract.'</th>
	                <th style="min-width: 80px;background: #4f81bd;height: 30px;color: white;font-size: 16px;font-weight: bold;">'.$l_totalValue_contract.'</th>
	                <th style="min-width: 80px;background: #4f81bd;height: 30px;color: white;font-size: 16px;font-weight: bold;">'.$l_prepaidMoney_contract.'</th>
	                <th style="min-width: 90px;background: #4f81bd;height: 30px;color: white;font-size: 16px;font-weight: bold;">'.$l_expectedDay_contract.'</th>
	                <th style="min-width: 100px;background: #4f81bd;height: 30px;color: white;font-size: 16px;font-weight: bold;">'.$l_nameCompany_contract.'</th>
	            </tr>
				<tr style="background: #d0d8e8;" height="40px">
					                <td style="font-size: 16px;text-align: left;">'.$name.'</td>
					                <td style="text-align:center;font-size: 16px;">'.$signDay.'</td>
					                <td style="text-align:left;font-size: 16px;">'.$content.'</td>
					                <td style="text-align:right;font-size: 16px;">'.number_format($totalValue).'</td>
					                <td style="text-align:right;font-size: 16px;">'.number_format($prepaidMoney).'</td>
					                <td style="text-align:center;font-size: 16px;">'.$expectedDay.'</td>
					                <td style="font-size: 16px;text-align: left;">'.$nameCompany.'</td>
				</tr>
				</tbody>
				</table>
				</body>
				</html>';


$body .='<br><table width="100%" style="padding:20px" >
	<tr><td align="right"><b>'.$l_sender.':</b> <b><i>'.$username.'</i></b></td></tr>
	</table>';
	
//echo $body;
$mail->Body = $body;
	
if(!$mail->Send()) {
  	echo "Mailer Error: " . $mail->ErrorInfo;
} else {
 	echo "Sent Successfully";
}
 mysql_close($connection);
 
 ?>